//
//  HPRecordItemView.m
//  HPZZTong
//
//  Created by handpay on 14-10-22.
//  Copyright (c) 2014年 handpay. All rights reserved.
//

#import "HPRecordItemView.h"
#import "DefineUtil.h"
#import "CategoryUtil.h"
#import "Utility.h"
#import "ZZTongDefine.h"

@interface HPRecordItemView ()

@property(nonatomic, retain) NSDictionary* dataDic;


@end

@implementation HPRecordItemView

@synthesize viewH;

- (id)initWithFrame:(CGRect)frame data:(NSDictionary*)data{
    self = [super initWithFrame:frame];
    if (self) {
        self.dataDic = data;
        [self initialize];
    }
    return self;
}
- (void)initialize{
    if (self.dataDic) {
        int h = [self createItemData:self.dataDic withTop:10];
        self.viewH = h;
    }
}

- (int)createItemData:(NSDictionary *)dic withTop:(int)top{
    
    if (!dic || dic.count == 0) {
        return 0;
    }
    
    self.backgroundColor = [UIColor whiteColor];
    
    int y = top;
    int x = 15;
    int lineH = 30;
    int labelW = self.frame.size.width - 2 * x;
    int statusW = 65;
    
    NSString* rwdTime = [dic objectForKey:@"rwdTime"];
    NSString* rwdStatus = [dic objectForKey:@"rwdStatus"];
    NSString* rwdMoney = [dic objectForKey:@"rwdMoney"];
    NSString* wdMoney = [dic objectForKey:@"wdMoney"];
    
    rwdTime = [@"申请时间： " stringByAppendingString:[Utility getFormatDate:rwdTime format:@"yyyyMMdd HH:mm:ss"]];
    
    UILabel* timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, labelW - statusW, lineH)];
    timeLabel.text = rwdTime;
    timeLabel.textColor = [UIColor blackColor];
    timeLabel.textAlignment = NSTextAlignmentLeft;
    timeLabel.font = kNormalFont;
    [self addSubview:timeLabel];
    [timeLabel release];
    
    UILabel* statusLabel = [[UILabel alloc]initWithFrame:CGRectMake(x + labelW - statusW + 5, top, statusW, lineH)];
    statusLabel.textAlignment = NSTextAlignmentLeft;
    statusLabel.font = kNormalFont;
    if ([rwdStatus isEqualToString:@"00"]) {
        statusLabel.textColor = [UIColor blackColor];
        statusLabel.text = @"申请成功";
    }else{
        statusLabel.textColor = [UIColor redColor];
        statusLabel.text = @"申请失败";
    }
    [self addSubview:statusLabel];
    [statusLabel release];
    
    y += 10 + lineH;
    
    if([rwdStatus isEqualToString:@"00"]){
    
        lineH -= 9;
        y -= 5;
    
        rwdMoney = [@"申请提现金额: " stringByAppendingString:[Utility getFormatMoneyAndSymbol:rwdMoney]];
        UILabel* applyLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, labelW, lineH)];
        applyLabel.text = rwdMoney;
        applyLabel.textColor = kNormalFontColor;
        applyLabel.textAlignment = NSTextAlignmentLeft;
        applyLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:applyLabel];
        [applyLabel release];
    
        y += lineH;
    
        wdMoney = [@"实际提现金额: " stringByAppendingString:[Utility getFormatMoneyAndSymbol:wdMoney]];
        UILabel* amountLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, labelW, lineH)];
        amountLabel.text = wdMoney;
        amountLabel.textColor = kNormalFontColor;
        amountLabel.textAlignment = NSTextAlignmentLeft;
        amountLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:amountLabel];
        [amountLabel release];
    
        y += 10 + lineH;
    }
    
    UIView* lineView = [[UIView alloc]initWithFrame:CGRectMake(x, y, labelW, 1)];
    lineView.backgroundColor = kNormalFontColor;
    [self addSubview:lineView];
    [lineView release];
    
    y += 1;
    
    CGRect frame = self.frame;
    frame.size.height = y;
    self.frame = frame;
    return  y;
}
- (void) awakeFromNib
{
    [self initialize];
}

- (void)dealloc{
    self.dataDic = nil;
    [super dealloc];
}
@end
